#include "RstpComm.h"
#include "CommonOpt.h"




string RstpVersion(UInt8 uiVer/*=RSTP_VERSION*/)
{
	char buf[8];
	sprintf(buf, "%d.%d", uiVer> 4, uiVer & 0x0F);
	string strTmp = buf;
	return strTmp;
}


UInt32 SRstpCommHead::OutAsData( char * outBuf, UInt32 bufLen )
{
	if(!outBuf || bufLen < Size())
		return 0;
	
	PacketHandler Handler(outBuf,bufLen);
	Handler<<Version<<ChnID<<RequestID<<DataLen<<SeqNo<<Total;
	return Handler.Size();
}

Bool SRstpCommHead::Parse( const char * pBuff, UInt32 vBuffLen )
{
	if(!pBuff || vBuffLen < Size())
		return FALSE;
	
	PacketHandler Handler(pBuff,vBuffLen);
	Handler>>Version>>ChnID>>RequestID>>DataLen>>SeqNo>>Total;

	if ( Version != RSTP_VERSION ) 
		return FALSE;
	
	if(Handler.Size() == Size())
		return TRUE;
	return FALSE;
}


